﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.EntityClient;

namespace dasFX.VSTime.API
{
    public interface ISolutionRepository : IRepository<Solution, VSTimeEntities>
    {
        Solution GetByFileName(string filename);
        int CreateSolution(Solution s);
    }

    public class SolutionRepository : Repository<Solution, VSTimeEntities>,  ISolutionRepository
    {
        public SolutionRepository() : base (new VSTimeEntities(new EntityConnection(SQLSubmitEvent.BuildEntityConnectionString(string.Empty))))
        { 
            
        }

        public Solution GetByFileName(string filename)
        {
            return this.DoQuery("Solution").Where(x => x.SolutionFileName == filename).FirstOrDefault();
        }

        public int CreateSolution(Solution s)
        {
            Add(s);
            Save();
            return s.ID;
        }
    }
}
